﻿using AdminBase.Model;
using Microsoft.AspNetCore.Http;

namespace AdminBase.Common.Helpers
{
    /// <summary>
    /// 返回结果类
    /// </summary>
    public class ResultHelper
    {
        /// <summary>
        /// 成功结果
        /// </summary>
        /// <param name="res">结果集</param>
        /// <param name="msg">描述</param>
        /// <returns></returns>
        public static ApiResult Success(object res, string msg = "成功")
        {
            return new ApiResult()
            {
                Code = StatusCodes.Status200OK,
                IsSuccess = true,
                Message = msg,
                Data = res
            };
        }

        /// <summary>
        /// 错误结果
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="statusCodes">错误代码</param>
        /// <param name="errors">错误集</param>
        /// <returns></returns>
        public static ApiResult Error(string message, int statusCodes = StatusCodes.Status400BadRequest, object? errors = null)
        {
            return new ApiResult()
            {
                Code = statusCodes,
                IsSuccess = false,
                Message = message,
                Errors = errors
            };
        }
    }
}
